<template>
	<view class="content">
		<view class="nav">
			<view class="cont" v-for="(item,index) in arr1" :key="index" @click="select(index,item.text)"
				:class="currentindex==index?'conts':''">
				{{item.text}}
			</view>
		</view>


		<view class="ifobox" v-for="(item,index) in arr" :key="index" v-if="topshow=='待核实' || topshow=='待完善'">
			<view class="left">
				<view class="top">
					<text class="plotname">{{item.name}}</text>
				</view>
				<view class="dwon">
					<text class="telephone">{{item.contact_number}}</text>
					<text class="name">{{item.contact}}</text>
				</view>
				<view class="policebox">
					<image src="https://fangguaner.wm76.mtnet.ren/static/applet/jincha.png" mode="" class="police">
					</image>
					<text class="dwell">{{item.community}}</text>
					<text class="username">{{item.guard}}</text>
				</view>
			</view>
			<view class="right" @click="examinedbtn(item.id)" v-if="item.status==0">
				核实
			</view>
			<view class="rightfinsh" @click="finishbtn(item.id,item.type)" v-if="item.status==1">
				完善房源
			</view>
		</view>

		<view class="wanshan" v-if="topshow!='待核实' && topshow!='待完善'">
			<BaseHouseList :arr="arr" :type="8" @issue="issue" @revocation="revocation" @xiugai="xiugai" @fabu="fabu"
				@finishxiugai="finishxiugai" @xiangqing="xiangqing"></BaseHouseList>
		</view>


	</view>
</template>

<script>
	import {
		getunexamined,
		houselist,
		getannounce
	} from "../../api/api/index.js"
	import {
		getexamined
	} from "../../api/api/index.js"
	import BaseHouseList from "../../components/BaseHouseList1/index.vue"
	export default {
		data() {
			return {
				arr: [],
				limit: 8,
				page: 0,
				isOk: false,
				currentindex: 0,
				type: "",
				arr1: [{
					text: "待核实"
				}, {
					text: "待完善"
				}, {
					text: "待发布"
				}, {
					text: "已发布"
				}, {
					text: "已下架"
				}],
				topshow: "待核实"
			}
		},
		methods: {
			select(index, item) {
				this.currentindex = index
				this.topshow = item
				this.arr = []
				this.isOk = false
				this.page = 0
				this.gethouselist()
			},
			examinedbtn(id) {
				let data = {
					id: id
				}
				let that = this
				getexamined(data).then(res => {
					that.isOk = false
					that.arr = []
					that.page = 0
					that.limit = 8
					that.gethouselist()
				})
			},
			gethouselist() {
				if (this.isOk) {
					return uni.showToast({
						icon: 'none',
						title: '没有更多了'
					})
				}
				uni.showLoading({
					mask: true,
					title: '加载中'
				})
				this.page++
				let data = {
					page: this.page,
					limit: this.limit,
					type: this.topshow
				}
				houselist(data).then(res => {
					uni.hideLoading()
					if (this.topshow == "已发布" || this.topshow == "已下架" || this.topshow == "待发布") {
						let arr = res.data.map(v => {
							v.house_id = v.id
							this.type = v.type
							v.statusa = v.status
							v = {
								...v,
								...v.house
							}
							return v
						})
						this.arr = this.arr.concat(arr)
						if (res.data.length < this.limit) {
							this.isOk = true
						}
					} else {
						this.arr = this.arr.concat(res.data)
						if (res.data.length < this.limit) {
							this.isOk = true
						}
					}

				})
			},
			// 发布
			fabu(e) {
				let data = {
					status: 1,
					id: e.guard_house_id
				}
				getannounce(data).then(res => {
					this.arr = []
					this.isOk = false
					this.page = 0
					this.gethouselist()
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 1500
					})
				})
			},
			// 详情
			xiangqing(e){
				this.jumpLink({link:"/pages/particulars/index",query:{id:e.id,type:e.type}})
			},
			// 修改
			xiugai(e) {
				if (e.type == 2) {
					this.jumpLink({
						link: "/pages/rentshoumaintain/index",
						query: {
							up: "修改",
							id: e.guard_house_id
						}
					})
				} else {
					this.jumpLink({
						link: "/pages/ershoumaintain/index",
						query: {
							up: "修改",
							id: e.guard_house_id
						}
					})
				}
			},
			//已经发布修改
			finishxiugai(e) {
				if (e.type == 2) {
					this.jumpLink({
						link: "/pages/rentshoumaintain/index",
						query: {
							up: "修改",
							id: e.guard_house_id
						}
					})
				} else {
					this.jumpLink({
						link: "/pages/ershoumaintain/index",
						query: {
							up: "修改",
							id: e.guard_house_id
						}
					})
				}
			},

			finishbtn(id, type) {
				if (type == 2) {
					this.jumpLink({
						link: "/pages/rentshoumaintain/index",
						query: {
							id: id
						}
					})
				} else {
					this.jumpLink({
						link: "/pages/ershoumaintain/index",
						query: {
							id: id
						}
					})
				}
				// this.jumpLink({
				// 	link: "/pages/uplaoding/index",
				// 	query: {
				// 		id: id,
				// 		showssa: "完善",
				// 		up: "修改",
				// 		type: type
				// 	}
				// })
			},

			issue(e) {
				let that = this
				uni.showLoading({
					title: '加载中'
				});

				setTimeout(function() {
					uni.hideLoading();
				}, 1000);
				setTimeout(function() {
					let data = {
						id: e.guard_house_id,
						status: 1
					}
					getannounce(data).then(res => {
						that.arr = []
						that.isOk = false
						that.page = 0
						that.gethouselist()
					})
				}, 1000);

			},
			revocation(e) {
				let that = this
				uni.showLoading({
					title: '加载中'
				});

				setTimeout(function() {
					uni.hideLoading();
				}, 1000);
				setTimeout(function() {
					let data = {
						id: e.guard_house_id,
						status: 0
					}
					getannounce(data).then(res => {
						that.arr = []
						that.isOk = false
						that.page = 0
						that.gethouselist()
					})
				}, 1000);
			}
		},
		onLoad() {},
		onShow() {
			this.arr = []
			this.isOk = false
			this.page = 0
			this.gethouselist()
		},
		components: {
			BaseHouseList
		},
		onReachBottom() {
			this.gethouselist()
		}

	}
</script>

<style>
	.content {
		position: absolute;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
	}


	/* 头部导航 */
	.nav {
		display: flex;
		justify-content: space-between;
		padding: 20rpx 21rpx;
		box-sizing: border-box;
		width: 100%;
		background-color: #FFFFFF;
	}

	.cont {
		width: 300rpx;
		height: 54rpx;
		background-color: #FFFFFF;
		border-radius: 10rpx;
		font-size: 24rpx;
		line-height: 54rpx;
		text-align: center;
	}

	.conts {
		color: #FFFFFF;
		background-color: #E32D24;
	}




	.ifobox {
		display: flex;
		justify-content: space-between;
		margin: 29rpx 20rpx;
		background-color: #FFFFFF;
		box-shadow: 3rpx 4rpx 7rpx 0rpx rgba(180, 180, 180, 0.46);
		border-radius: 10rpx;
		padding: 40rpx 26rpx 22rpx 36rpx;
		box-sizing: border-box;
	}

	.plotname {
		font-family: MicrosoftYaHei-Bold;
		font-size: 30rpx;
		font-weight: 700;
		font-stretch: normal;
		color: #000000;
	}

	.square {
		font-size: 28rpx;
		font-weight: 700;
		font-stretch: normal;
		letter-spacing: 0rpx;
		color: #282828;
		margin-left: 23rpx;
		font-family: MicrosoftYaHei-Bold;
	}

	.dwon {
		margin-top: 20rpx;
	}

	.telephone {
		font-family: PingFang-SC-Heavy;
		font-size: 24rpx;
		font-weight: normal;
		font-stretch: normal;
		color: #666666;
	}

	.name {
		font-family: PingFang-SC-Heavy;
		font-size: 24rpx;
		font-weight: normal;
		font-stretch: normal;
		color: #666666;
		margin-left: 20rpx;
	}

	.policebox {
		margin-top: 49rpx;
	}

	.police {
		width: 25rpx;
		height: 39rpx;
	}

	.dwell {
		font-family: MicrosoftYaHei;
		font-size: 24rpx;
		font-weight: normal;
		font-stretch: normal;
		color: #666666;
		margin-left: 18rpx;
	}

	.username {
		font-family: MicrosoftYaHei;
		font-size: 24rpx;
		font-weight: normal;
		font-stretch: normal;
		color: #666666;
		margin-left: 18rpx;
	}

	.right {
		font-family: MicrosoftYaHei;
		font-size: 26rpx;
		font-weight: normal;
		font-stretch: normal;
		color: #993300;
		width: 128rpx;
		height: 60rpx;
		background-color: #ffcc00;
		border-radius: 30rpx;
		text-align: center;
		line-height: 60rpx;
		margin-top: 12rpx;
	}

	.rightfinsh {
		font-family: MicrosoftYaHei;
		font-size: 26rpx;
		font-weight: normal;
		font-stretch: normal;
		color: #FFFFFF;
		width: 128rpx;
		height: 60rpx;
		background-color: #f75653;
		border-radius: 30rpx;
		text-align: center;
		line-height: 60rpx;
		margin-top: 12rpx;
	}

	.wanshan {
		padding-left: 10rpx;
		box-sizing: border-box;
	}
</style>
